package iec104_client

import (
	"github.com/sirupsen/logrus"
	iec104_apdu "go-iot-gateway/pkg/iec104/apdu"
	"time"
)

type OnConnectHandler func()
type OnMessageHandler func(*iec104_apdu.APDU)
type ConnectionLostHandler func()

//type ReconnectHandler func(*Iec104Client, *ClientOptions)

// 发送消息
type MessageHandler func(*Iec104Client)

type ClientOptions struct {
	Address              string
	SubAddress           string //todo 子通道
	Logger               *logrus.Logger
	ConnectTimeout       time.Duration
	ConnectRetry         bool
	WriteTimeout         time.Duration
	OnConnect            OnConnectHandler
	KeepAlive            int64
	MaxReconnectInterval time.Duration
	AutoReconnect        bool
	ConnectRetryInterval time.Duration
	OnConnectionLost     ConnectionLostHandler
	OnMessageHandler     OnMessageHandler
	//OnReconnecting       ReconnectHandler
	TotalCallInterval time.Duration //总召间隔
	WriteChanSize     int           //写通道大小
	ReadChanSize      int           //读通道大小
	NetConnDeadline   time.Duration //设置TCP连接的超时时间, 如果在超时时间内没有收到任何数据，则连接将被关闭
	ReadRetryInterval time.Duration //当读取到空数据后,等多少秒重次再读
}

func NewClientOptions() *ClientOptions {
	o := &ClientOptions{
		Address:              "127.0.0.1:2404",
		ConnectRetry:         true,
		ConnectTimeout:       7 * time.Second,
		ConnectRetryInterval: 3 * time.Second,

		MaxReconnectInterval: 3 * time.Second,
		AutoReconnect:        true,

		WriteTimeout: 7 * time.Second,

		WriteChanSize: 100,
		ReadChanSize:  700,

		NetConnDeadline:   10 * 60 * time.Second, //10 分钟
		ReadRetryInterval: 3 * time.Second,
		Logger:            logrus.New(),
	}
	return o
}
